package org.example.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.pojo.Order;
import org.example.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

@Slf4j
@RestController
@RequestMapping("/api/order")
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("")
    public Order getOrderInfo(Integer orderNo){

        return orderService.getOrderInfo(orderNo);
    }

    /**
     * 测试feignClient指定断路器
     * @param orderNo
     * @return
     */
    @GetMapping("/{orderNo}")
    public Order getOrderInfo2(@PathVariable Integer orderNo){

        return orderService.getOrderInfo2(orderNo);
    }
    @GetMapping("/list")
//    测试hystrix合并请求
    public Order getOrderInfoList() throws ExecutionException, InterruptedException {
        Future<Order> orderFuture1 = orderService.getFutureOrderInfo(110);
        Future<Order> orderFuture2 = orderService.getFutureOrderInfo(123);
        Future<Order> orderFuture3 = orderService.getFutureOrderInfo(4123);
        Future<Order> orderFuture4 = orderService.getFutureOrderInfo(41255);
        Future<Order> orderFuture5 = orderService.getFutureOrderInfo(5556);
        Future<Order> orderFuture6 = orderService.getFutureOrderInfo(676);
        log.info("{}",orderFuture1.get());
        log.info("{}",orderFuture2.get());
        log.info("{}",orderFuture3.get());
        log.info("{}",orderFuture4.get());
        log.info("{}",orderFuture5.get());
        log.info("{}",orderFuture6.get());
        return orderFuture6.get();
    }

    @GetMapping("/{orderNo}/product/list")
    public List getOrderProductList(@PathVariable Integer orderNo){
        return orderService.getProductList();
    }

}
